using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace WebCrawlerTools.data
{
    class Log
    {
        private static Log pThis;
        private string path;
        private string filename = "\\crawler.log";
        private LogLevelType level;

        public String Path
        {
            get
            {
                return path;
            }
            set
            {
                path = value;
            }
        }

        public LogLevelType Level
        {
            get
            {
                return level;
            }
            set
            {
                level = value;
            }
        }

        public static Log Inst()
        {
            if (null == pThis)
            {
                pThis = new Log();
            }
            return pThis;
        }

        public void Write(string s)
        {
            try
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                StreamWriter writer = new StreamWriter(path + filename, true, Encoding.Default);
                writer.Write(s);
                writer.Close();
            }
            catch (Exception e)
            {
                e.ToString();
            }
        }

        public void Write(string s, string fileName)
        {
            try
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                StreamWriter writer = new StreamWriter(path +"\\"+ fileName, true, Encoding.Default);
                writer.Write(s);
                writer.Close();
            }
            catch (Exception e)
            {
                e.ToString();
            }
        }
    }
    public enum LogLevelType
    {
        INFO = 1,
        WARING = 2,
        DEBUG = 4,
        ERROR = 8,
    }
}
